<?php

	require ('includes/functions.php');
	(checkSession())? $id=checkSession() : redirect();
	
	$query = "SELECT * FROM posts_table WHERE postToId=".$id." ORDER BY dateCreated DESC";
	$posts = mysql_query($query);
	$numPosts = mysql_num_rows($posts);
	
	$query1 = "SELECT * FROM user_table WHERE userId=".$id;
	$users = mysql_query($query1);
	$user = mysql_fetch_array($users);
	
?>
<?php include 'includes/header.php';?>
<div id="columns">				
	<div id="column-1" class="column menu"></div>				
	<div class="blocks">
		<table align = 'center' width = '513'>
			<tr >
				<td width='150' rowspan = "2">
					<img src='<?php echo 'user_images/'.$user['url']; ?>' height='170' width='150'/>
				</td>
			</tr>
			<tr>
				<td>
					<table align="center" class = 'post'>
						<tr>
							<td  style = 'text-align: left;' >
								<h2><?php echo "<a href='profile.php'>".$user['firstName']." ".$user['lastName']."</a>"; ?></h2>
							</td>
						</tr>
						<tr>
							<form action="submitPost.php" method="POST" name="postsForm">
							<td>
								<textarea class="input" id="watermark" name="post" style="resize:none;height:70px;" cols="45px"></textarea>
							</td>
						</tr>
						<tr>
							<td style = "text-align:right;"><input type="submit" value="Post" name = "submitPost"></td>
						</tr>
							</form>
					</table>
				</td>
			</tr>
		</table>
		<table width = '80%'  align = 'center' class="dPost">
			<?php for($i = 1; $i<=$numPosts; $i++ ): ?>
			<?php
				$post = mysql_fetch_array($posts);
				$posterQuery = "SELECT * FROM user_table WHERE userId = ".$post['userId'];
				$poster = mysql_query($posterQuery);
				$poste = mysql_fetch_array($poster);
			?>	
				<tr>
					<td colspan = '2'>
						<hr style = 'height:0px; border-style:solid; border-width:2px 0 0 0;border-color:#ccc;}'/>
					</td>
				</tr>
				<tr>
					<td width = "20%">
						<a href='profile.php?id='".$id."'><img src="user_images/<?php echo $poste['url'];?>" height='80' width='80'/></a>
					</td>
					<td style = 'text-align : left; '>
					<a href = "viewProfile.php?id=<?php echo $poste['userId']; ?>"><h3><?php echo $poste['firstName']. " ".$poste['lastName']; ?></h3></a>
					</td>
				</tr>
				<tr height = '40px'>
				<td></td><td  style = 'text-align : left;'><table  style = 'text-align : left;'>
						<tr>										
							<td>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<?php echo $post['post']; ?>
							</td>
						</tr>
					</table>
				</td>							
				</tr>
				<tr  height = '25px'></tr>
			<?php endfor; ?>
		</table>
	</div>
	<div id="column-3" class="column sidebar"></div>

<?php include 'includes/footer.php';?>	